<?php 
include_once('includes.php'); 

$where=" where  1  ";
//paging--------------
include_once('../includes/paging.class.php');

$q_str = $_SERVER['QUERY_STRING'];
if(isset($_GET['page']))
{
  $q_str = str_replace('page='.$_GET['page'],'',$_SERVER['QUERY_STRING']);    
}
$sql = "select count(*) as total from video $where ";
$r=db_fetch_one($sql);
$total=$r->total;

$paging = new Paging();

$paging->assign ( 'video?'.$q_str ,  $total , 20 );
$limit = ' Limit '.$paging->sql_limit();

//-------------------
	
$sql = "select  * from video $where order by date_created desc $limit";
$videos=db_fetch_all($sql);

?>
<?php include_once('includes/header.php'); 	 ?>
<span class="title">Video </span>

<a href="create-video" title="Create new video">Create new video</a>

<table> 
	<thead>
		<tr>
			<th> Thumb </th>
			<th> Title</th>
			<th> Date created</th>
			
			<th> </th>
		</tr>
	</thead>
	
<?php 
foreach($videos as $video)
{
	
?>
	<tr>
		<td><img src="<?php echo $video->thumb_image;?>" width="100px" height="60px" /></td>
		<td><?php echo $video->title;?></td>
		<td><?php echo formatOutputDate($video->date_created);?></td>
		<td><a href="create-video?id=<?php echo $video->id; ?>">Edit</a> | <a onclick="if(!confirm('Do you want to delete this video?')) return false;" href="create-video?task=delete&id=<?php echo $video->id; ?>">Delete</a></td>
	</tr>
<?php
}
?>
</table>

<div class="pager">
<?php
	echo $paging->fetch();
?>
</div>
<?php include_once('includes/footer.php'); 	 ?>